package com.exemplo.flickrsocial.persistence;

import com.exemplo.flickrsocial.util.StringUtils;
import com.gmail.yuyang226.flickr.FlickrException;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

/**
 * 
 * @author Douglas
 * 
 */
public class SharedFlickr {

	private static SharedPreferences settings;

	private SharedFlickr() {

	}

	/**
	 * Create an sharedPreferences
	 * 
	 * @param context
	 * @throws FlickrException
	 */
	public static void sharedCreate(Context context) throws FlickrException {

		// Restore preferences
		settings = context.getSharedPreferences(StringUtils.PREFS_NAME,
				Context.MODE_PRIVATE);

	}

	/**
	 * get Token
	 * 
	 * @return
	 */
	public static String getOauthToken() {

		return settings.getString(StringUtils.KEY_OAUTH_TOKEN, null);

	}

	/**
	 * get tokensecrent
	 * 
	 * @return
	 */
	public static String getOauthTokenSecrent() {

		return settings.getString(StringUtils.KEY_TOKEN_SECRET, null);

	}

	/**
	 * get name
	 * 
	 * @return
	 */
	public static String getUserName() {

		return settings.getString(StringUtils.KEY_USER_NAME, null);
	}

	/**
	 * get user id
	 * 
	 * @return
	 */
	public static String getUserID() {

		return settings.getString(StringUtils.KEY_USER_ID, null);
	}

	/**
	 * 
	 * save the object token
	 * 
	 * @param userName
	 * @param userId
	 * @param token
	 * @param tokenSecret
	 */
	public static void savedOauthToken(String userName, String userId,
			String token, String tokenSecret) {

		Editor editor = settings.edit();
		editor.putString(StringUtils.KEY_OAUTH_TOKEN, token);
		editor.putString(StringUtils.KEY_TOKEN_SECRET, tokenSecret);
		editor.putString(StringUtils.KEY_USER_NAME, userName);
		editor.putString(StringUtils.KEY_USER_ID, userId);
		editor.commit();
	}

}
